package org.springblade.modules.mes.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springblade.core.tool.api.R;
import org.springblade.modules.mes.base.entity.LMSDetail;
import org.springblade.modules.mes.base.entity.StationAssembly;
import org.springblade.modules.mes.base.service.ILmsProductionOrderService;
import org.springblade.modules.mes.base.service.IStationAssemblyService;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 产品BOM信息 控制器
 *
 * @author BladeX
 * @since 2021-03-11
 */
@RestController
@AllArgsConstructor
@RequestMapping("/v1/prd")
@Api(value = "数采开放API", tags = "数采开放API")
@Slf4j
public class PrdApiController {

	private final IStationAssemblyService stationAssemblyService;

	private final ILmsProductionOrderService lmsProductionOrderService;


	@GetMapping("/repair")
	@ApiOperation(value = "返修标记", notes = "标记")
	public R<Object> repair(@RequestParam String station, @RequestParam String assemblyBarCode) throws Exception {
		StationAssembly stationAssembly = stationAssemblyService.getOne(new QueryWrapper<StationAssembly>().lambda().eq(StationAssembly::getStationCode, station)
			.eq(StationAssembly::getAssemblyBarcode, assemblyBarCode));
		stationAssembly.setStatus(4);
		stationAssemblyService.updateById(stationAssembly);

		LMSDetail lmsDetail = lmsProductionOrderService.getOne(new QueryWrapper<LMSDetail>().lambda()
			.eq(LMSDetail::getBarCode, assemblyBarCode));
		lmsDetail.setStatus(4);
		lmsProductionOrderService.updateById(lmsDetail);
		return R.success("标记成功");
	}

	@GetMapping("/handArchive")
	@ApiOperation(value = "返修标记", notes = "标记")
	public R<Object> handArchive(@RequestParam String station) throws Exception {
		return R.success("归档成功");

	}
}
